2 // Just to make sure the input is well formed and there are no three
3 // consecutive collineal points in the border of the resulting polygon.
26 #define foreach(x, v) for (typeof (v).begin() x=(v).begin(); x !=(v).end(); ++x)
27 #define For(i, a, b) for (int i=(a); i<(b); ++i)
28 #define D(x) cout << #x " is " << x << endl
30 const int MAXC
= 1035;
32 typedef pair
< int, int > point
;
33 typedef pair
< point
, point
> side
;
35 vector
< int > YgivenX
[MAXC
], XgivenY
[MAXC
];
38 bool isSimpleClosedPolygon() {
39 point start
= sides
[0].first
;
48 printf("Inserted <%d, %d>\n", cur
.first
, cur
.second
);
49 for (int i
= 0; i
< sides
.size(); ++i
) {
50 if (sides
[i
].first
== cur
or sides
[i
].second
== cur
) {
51 next
= sides
[i
].first
== cur
? sides
[i
].second
: sides
[i
].first
;
53 if (seen
.count(next
) == 0) {
58 printf("next = <%d, %d>\n", next
.first
, next
.second
);
60 } while (cur
!= start
);
62 return seen
.size() == sides
.size();
67 while (cin
>> n
>> m
) {
68 if (n
== 0 and m
== 0) break;
72 For(i
, 0, MAXC
) YgivenX
[i
].clear(), XgivenY
[i
].clear();
75 int x
, y
; cin
>> x
>> y
;
76 XgivenY
[y
].push_back( x
);
77 YgivenX
[x
].push_back( y
);
80 cin
>> x1
>> y1
>> x2
>> y2
;
85 sort(YgivenX
[x
].begin(), YgivenX
[x
].end());
86 assert(YgivenX
[x
].size() % 2 == 0);
87 for (int k
= 0; k
< YgivenX
[x
].size(); k
+= 2) {
88 int y
= YgivenX
[x
][k
];
89 int nextY
= YgivenX
[x
][k
+1];
91 sides
.push_back( side(point(x
, y
), point(x
, nextY
)) );
96 sort(XgivenY
[y
].begin(), XgivenY
[y
].end());
97 assert(XgivenY
[y
].size() % 2 == 0);
98 for (int k
= 0; k
< XgivenY
[y
].size(); k
+= 2) {
99 int x
= XgivenY
[y
][k
];
100 int nextX
= XgivenY
[y
][k
+1];
102 sides
.push_back( side(point(x
, y
), point(nextX
, y
)) );
106 assert(sides
.size() == n
);
107 for (int i
= 0; i
< sides
.size(); ++i
) {
108 printf("There's a side from <%d, %d> to <%d, %d>\n", sides
[i
].first
.first
, sides
[i
].first
.second
, sides
[i
].second
.first
, sides
[i
].second
.second
);
110 assert(isSimpleClosedPolygon());